#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mem(x) memset(x,0,sizeof(x))
#define endl "\n"
#define printYes cout << "Yes\n"
#define printYES cout << "YES\n"
#define printNo cout << "No\n"
#define printNO cout << "NO\n"
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,j,k) for (int i=(j);i<=(k);i++)
#define per(i,j,k) for (int i=(j);i>=(k);i--)
#define pcnt(x) __builtin_popcount(x)
mt19937 rnd(time(0));
template<class T>void chkmin(T&x,T y){x=min(x,y);}
template<class T>void chkmax(T&x,T y){x=max(x,y);}

const ll inf=1000000000000000000; 
//const ll inf=1000000000;
//const ll mod=998244353;
//const ll mod=1000000007;

const int N=1000005;
int n,m; 
int sa[N],rk[N],dp[N],tmp[N];
vector<int>t[N];
vector<pii>g;
bool flag;
inline void add(int x,int y)
{
	//cerr << x << " " << y << endl;
	if (x==y)
	{
		flag=0;
		return;
	}
	if (x<0||y<0) return;
	if (rk[x]>rk[y]) swap(x,y);
	g.pb(mkp(x,y));
}
int a[N*2],b[N*2],R[N*2];
int fa[N];
int find(int x)
{
	if (x==fa[x]) return x;
	return fa[x]=find(fa[x]); 
}
void assign(int l,int r)
{
	for (l=find(l);l<r;l=find(l)) fa[l]=l+1;
}
void make(int x,int y)
{
	if (x<0||y<0) return;
	if (rk[x]>rk[y]) swap(x,y);
	assign(rk[x],rk[y]);
}

void work()
{
	flag=1;
	cin >> n;
	rep(i,1,n) cin >> sa[i];
	rep(i,1,2*n-1) cin >> b[i];
	rep(i,1,n) sa[i]++;
	rep(i,1,n) if (sa[i]<1||sa[i]>n)
	{
		cout << "-1\n";
		return;
	}
	rep(i,1,n) rk[i]=-1;
	rep(i,1,n) rk[sa[i]]=i;
	rep(i,1,n) 
	{
		if (rk[i]==-1)
		{
			cout << "-1\n";
			return;
		}
	}
	rk[n+1]=-1;
	rep(i,1,n) t[i].clear();
	g.clear();
	rep(i,1,n-1)
	{
		if (rk[sa[i]+1]>rk[sa[i+1]+1]) add(sa[i],sa[i+1]);
	}
	int cnt=1;
	a[1]=1;
	rep(i,2,n) a[++cnt]=-1,a[++cnt]=i;
	a[cnt+1]=-2,a[0]=-3;
	rep(i,1,n+1) fa[i]=i;
	rep(i,1,2*n-1)
	{
		int r=0;
		if (i%2==1)
		{
			if (b[i]%2==0) flag=0;
			else r=b[i]/2*2+1;
		}
		else
		{
			if (b[i]%2==1) flag=0;
			else r=b[i];
		}
		if (i-r==0||i+r==cnt+1) r--;
		if (r>=0&&(i-r<1||i+r>cnt)) flag=0;
		else
		{
			add(a[i-r-1],a[i+r+1]);
			R[i]=r+1;
		}
	}
	if (flag==0)
	{
		cout << "-1\n";
		return;
	}
	int mid=1,mx=1;
	rep(i,1,cnt)
	{
		int r;
		if (i<mx) r=min(mx-i+1,R[mid*2-i]);
		else r=1;
		while (r<R[i])
		{
			make(a[i-r],a[i+r]);
			r++;
		}
		if (r!=R[i]) flag=0;
	}
	if (flag==0)
	{
		cout << "-1\n";
		return;
	}
	for (pii i:g)
	{
		int x=find(rk[i.fi]),y=find(rk[i.se]);
		if (x==y)
		{
			cout << "-1\n";
			return;
		}
		t[y].pb(x);
	}
	rep(i,1,n) dp[i]=0;
	rep(i,1,n) 
	{
		dp[i]=dp[i-1];
		for (int j:t[i]) chkmax(dp[i],dp[j]+1);
	}
	if (dp[n]>25)
	{
		cout << "-1\n";
		return;
	}
	rep(i,1,n) cout << (char)('a'+dp[find(rk[i])]);
	cout << "\n";
	// rep(i,1,n) cout << find(i) << " ";
	// cout << endl;
}

int main()
{
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;
	cin >> T;
	while (T--) work();
	return 0;
}
